package com.dnjn.mes.biz.service.impl;

import com.dnjn.mes.biz.domain.MesWorkforceShift;
import com.dnjn.mes.biz.domain.MesWorkforceShiftClocking;
import com.dnjn.mes.biz.mapper.MesWorkforceShiftClockingMapper;
import com.dnjn.mes.biz.service.IMesWorkforceShiftClockingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dnjn.mes.biz.service.IMesWorkforceShiftService;
import com.dnjn.mes.common.constant.Constants;
import com.dnjn.mes.common.exception.ServiceException;
import com.dnjn.mes.common.exception.user.UserPasswordNotMatchException;
import com.dnjn.mes.common.utils.MessageUtils;
import com.dnjn.mes.framework.manager.AsyncManager;
import com.dnjn.mes.framework.manager.factory.AsyncFactory;
import com.dnjn.mes.framework.security.context.AuthenticationContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 打卡记录 服务实现类
 * </p>
 *
 * @author Amber
 * @since 2023-08-29
 */
@Service("iMesWorkforceShiftClockingService")
public class MesWorkforceShiftClockingServiceImpl extends ServiceImpl<MesWorkforceShiftClockingMapper, MesWorkforceShiftClocking> implements IMesWorkforceShiftClockingService {
    @Autowired
    private IMesWorkforceShiftService shiftService;
    @Override
    public MesWorkforceShiftClocking checkClockInOrOut(long equipmentId, Long userId,Long shiftId) {
        return baseMapper.checkClockInOrOut(equipmentId,userId,shiftId);
    }

    @Override
    public MesWorkforceShiftClocking checkClockUser(String date, Long equipmentId, Long userId) {
        return baseMapper.checkClockUser(date,equipmentId,userId);
    }

    @Override
    public void checkOutAll(Long shiftId,long equipmentId) {
        //同步更新shift表的一开始下班打卡, 同时将当前shift软删除，
        MesWorkforceShift shift = new MesWorkforceShift();
        shift.setShiftId(shiftId);
        shift.setHasClockout("1");
        shiftService.updateById(shift);
        baseMapper.checkOutAll(shiftId,equipmentId);
    }

    @Override
    public List<MesWorkforceShiftClocking> clockInRecords(String searchKey, long equipmentId) {
        return baseMapper.clockInRecords(searchKey,equipmentId);
    }
}
